<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item v-if="false" label="出生年月" prop="birthDate">
        <el-date-picker clearable
          v-model="queryParams.birthDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择出生年月">
        </el-date-picker>
      </el-form-item>
      <el-form-item label-width="100px" label="驾驶员姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入驾驶员姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item v-if="false" label="车队编号" prop="teamId">
        <el-input
          v-model="queryParams.teamId"
          placeholder="请输入车队编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="性别 " prop="sex">
        <el-select v-model="queryParams.sex" placeholder="请选择性别" clearable>
          <el-option
            v-for="dict in dict.type.sys_user_sex"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item  v-if="false" label="联系电话" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入联系电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item v-if="false" label="驾驶员身份ID" prop="icCard">
        <el-input
          v-model="queryParams.icCard"
          placeholder="请输入驾驶员身份ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label-width="100px" label="驾驶员类型" prop="driverType">
        <el-select v-model="queryParams.driverType" placeholder="请选择驾驶员类型" clearable>
          <el-option
            v-for="dict in dict.type.driver_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item v-if="false" label="准驾车型" prop="drivingLicenseType">
        <el-input
          v-model="queryParams.drivingLicenseType"
          placeholder="请输入准驾车型"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['driver:driverinfo:add']"
        >添加</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['driver:driverinfo:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['driver:driverinfo:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['driver:driverinfo:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="driverinfoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column v-if="false" label="主键" align="center" prop="id" />
      <el-table-column  label="驾驶员姓名"  label-width="100px" align="center" prop="name" />
      <el-table-column label="出生年月" align="center" prop="birthDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.birthDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>

      <el-table-column label="车队名称" align="center" prop="teamId" />
      <el-table-column label="性别" align="center" prop="sex">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_user_sex" :value="scope.row.sex"/>
        </template>
      </el-table-column>
      <el-table-column label="联系电话" align="center" prop="phone" />
      <el-table-column label="驾驶员身份" align="center" prop="icCard" />
<!--      <el-table-column label="身份证照片(最多2张)-附件" align="center" prop="idCardPhoto" />-->
<!--      <el-table-column label="人脸照片(最多8张)-附件" align="center" prop="facePhoto" />-->
<!--      <el-table-column label="健康证明(最多2张)-附件" align="center" prop="healthProof" />-->
      <el-table-column label="驾驶员类型" align="center" prop="driverType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.driver_type" :value="scope.row.driverType"/>
        </template>
      </el-table-column>
      <el-table-column label="准驾车型" align="center" prop="drivingLicenseType" />
      <el-table-column label="初次领证日期" align="center" prop="firstIssueDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.firstIssueDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="驾驶证有限期开始" align="center" prop="licenseValidFrom" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.licenseValidFrom, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="驾驶证有限期结束" align="center" prop="licenseValidTo" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.licenseValidTo, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column  label="驾驶证档案编号" label-width="150px" align="center" prop="licenseFileNumber" />
      <el-table-column label="驾驶证照片" align="center" prop="licensePhoto" />
<!--      <el-table-column label="从业资格信息-附件" align="center" prop="qualificationInfo" />-->
<!--      <el-table-column label="机动车驾驶员安全信用表-附件" align="center" prop="driverSafetyCreditTable" />-->
<!--      <el-table-column label="扩展位" align="center" prop="exts" />-->
<!--      <el-table-column label="数据状态" align="center" prop="status" />-->
<!--      <el-table-column label="关联用户账号userId" align="center" prop="userId" />-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['driver:driverinfo:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['driver:driverinfo:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改驾驶员信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="6">
        <el-form-item label="驾驶员姓名" label-width="100px" prop="name">
          <el-input v-model="form.name" placeholder="请输入驾驶员姓名" />
        </el-form-item>
            </el-col>

            <el-col :span="6">
        <el-form-item label="出生年月" prop="birthDate">
          <el-date-picker clearable
            v-model="form.birthDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择出生年月">
          </el-date-picker>
        </el-form-item>
              </el-col>


              <el-col :span="6">
        <el-form-item label="车队编号" prop="teamId">
          <el-input v-model="form.teamId" placeholder="请输入车队编号" />
        </el-form-item>
                </el-col>

          <el-col :span="6">
        <el-form-item label="性别" prop="sex">
          <el-select v-model="form.sex" placeholder="请选择性别">
            <el-option
              v-for="dict in dict.type.sys_user_sex"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
            </el-col>

          <el-col :span="6">
        <el-form-item label="联系电话" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入联系电话" />
        </el-form-item>
            </el-col>

          <el-col :span="6">
        <el-form-item label="驾驶员身份ID" label-width="100px" prop="icCard">
          <el-input v-model="form.icCard" placeholder="请输入驾驶员身份ID" />
        </el-form-item>
            </el-col>

          <el-col :span="6">
        <el-form-item label="身份证照片" label-width="100px"  prop="idCardPhoto">
          <el-input v-model="form.idCardPhoto" type="text" placeholder="身份证照片(最多2张)-附件" />
        </el-form-item>
            </el-col>

          <el-col :span="6">
        <el-form-item label="人脸照片" prop="facePhoto">
          <el-input v-model="form.facePhoto" type="text" placeholder="人脸照片(最多8张)-附件" />
        </el-form-item>
            </el-col>
          <el-col :span="6">
        <el-form-item label="健康证明" prop="healthProof">
          <el-input v-model="form.healthProof" type="text" placeholder="健康证明(最多2张)-附件" />
        </el-form-item>
            </el-col>
          <el-col :span="6">
        <el-form-item label="驾驶员类型" label-width="100px" prop="driverType">
          <el-select v-model="form.driverType" placeholder="请选择驾驶员类型">
            <el-option
              v-for="dict in dict.type.driver_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
            </el-col>

          <el-col :span="6">
        <el-form-item label="准驾车型" prop="drivingLicenseType">
          <el-input v-model="form.drivingLicenseType" placeholder="请输入准驾车型" />
        </el-form-item>
            </el-col>
          <el-col :span="6">
        <el-form-item label="初次领证日期" label-width="100px"  prop="firstIssueDate">
          <el-date-picker clearable
            v-model="form.firstIssueDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择初次领证日期">
          </el-date-picker>
        </el-form-item>
            </el-col>
          <el-col :span="6">
        <el-form-item label="驾驶证有限期开始" label-width="130px" prop="licenseValidFrom">
          <el-date-picker clearable
            v-model="form.licenseValidFrom"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择驾驶证有限期开始">
          </el-date-picker>
        </el-form-item>
            </el-col>

          <el-col :span="6">
        <el-form-item label="驾驶证有限期结束" label-width="130px" prop="licenseValidTo">
          <el-date-picker clearable
            v-model="form.licenseValidTo"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择驾驶证有限期结束">
          </el-date-picker>
        </el-form-item>
            </el-col>

          <el-col :span="6">
        <el-form-item label="驾驶证档案编号" label-width="120px" prop="licenseFileNumber">
          <el-input v-model="form.licenseFileNumber" placeholder="请输入驾驶证档案编号" />
        </el-form-item>
            </el-col>

          <el-col :span="6">
        <el-form-item label="驾驶证照片" label-width="100px" prop="licensePhoto">
          <el-input v-model="form.licensePhoto" type="text" placeholder="请输入内容" />
        </el-form-item>
            </el-col>

          <el-col :span="6">
        <el-form-item label="从业资格信息-附件" label-width="150px" prop="qualificationInfo">
          <el-input v-model="form.qualificationInfo" type="text" placeholder="请输入内容" />
        </el-form-item>
            </el-col>

          <el-col :span="6">
        <el-form-item label="机动车驾驶员安全信用表-附件" label-width="200px" prop="driverSafetyCreditTable">
          <el-input v-model="form.driverSafetyCreditTable" type="text" placeholder="请输入内容" />
        </el-form-item>
            </el-col>



          <el-col :span="6">
        <el-form-item label="关联用户账号userId" label-width="200px" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入关联用户账号userId" />
        </el-form-item>
            </el-col>
          </el-row>

      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listDriverinfo, getDriverinfo, delDriverinfo, addDriverinfo, updateDriverinfo } from "@/api/driver/driverinfo";

export default {
  name: "Driverinfo",
  dicts: ['sys_user_sex', 'driver_type'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 驾驶员信息表格数据
      driverinfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        birthDate: null,
        name: null,
        teamId: null,
        sex: null,
        phone: null,
        icCard: null,
        idCardPhoto: null,
        facePhoto: null,
        healthProof: null,
        driverType: null,
        drivingLicenseType: null,
        firstIssueDate: null,
        licenseValidFrom: null,
        licenseValidTo: null,
        licenseFileNumber: null,
        licensePhoto: null,
        qualificationInfo: null,
        driverSafetyCreditTable: null,
        exts: null,
        status: null,
        userId: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询驾驶员信息列表 */
    getList() {
      this.loading = true;
      listDriverinfo(this.queryParams).then(response => {
        this.driverinfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        birthDate: null,
        name: null,
        teamId: null,
        sex: null,
        phone: null,
        icCard: null,
        idCardPhoto: null,
        facePhoto: null,
        healthProof: null,
        driverType: null,
        drivingLicenseType: null,
        firstIssueDate: null,
        licenseValidFrom: null,
        licenseValidTo: null,
        licenseFileNumber: null,
        licensePhoto: null,
        qualificationInfo: null,
        driverSafetyCreditTable: null,
        exts: null,
        status: null,
        createTime: null,
        updateTime: null,
        userId: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加驾驶员信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getDriverinfo(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改驾驶员信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateDriverinfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDriverinfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除驾驶员信息编号为"' + ids + '"的数据项？').then(function() {
        return delDriverinfo(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('driver/driverinfo/export', {
        ...this.queryParams
      }, `driverinfo_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
